﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.原型
{
    public partial class Frm面料库存更改 : DevExpress.XtraEditors.XtraForm
    {
        public String fabric { get; set; }
        public Double VALUE { get; set; }

        public List<DTO库存记录> list = new List<DTO库存记录>();
        public Frm面料库存更改()
        {
            InitializeComponent();
        }

        public Frm面料库存更改(String fabric,String breadth,String quantity)
        {
            InitializeComponent();
            this.fabric = fabric;
            this.label面料号.Text = "面料号：" + fabric;
            this.label幅宽.Text = "幅宽：" + breadth;
            this.label剩余米数.Text = "剩余米数：" + quantity;
            this.list = FunctionHelper.JsonDeserialization<List<DTO库存记录>>(RestCall.httpGetMethod(URL.接口url + "/inventory/inventoryDetail?fabricNo=" + this.fabric));
            this.gridControl1.DataSource = this.list;
        }

        private void textBox增减值_KeyPress(object sender, KeyPressEventArgs e)
        {
			//允许输入数字、小数点、删除键和负号  
			if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
			{
				MessageBox.Show("请输入正确的数字");
				this.textBox增减值.Text = "";
				e.Handled = true;
			}
			if (e.KeyChar == (char)('-'))
			{
				if (textBox增减值.Text != "")
				{
					MessageBox.Show("请输入正确的数字");
					this.textBox增减值.Text = "";
					e.Handled = true;
				}
			}
			/*小数点只能输入一次*/
			if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
			{
				MessageBox.Show("请输入正确的数字");
				this.textBox增减值.Text = "";
				e.Handled = true;
			}
			/*第一位不能为小数点*/
			if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
			{
				MessageBox.Show("请输入正确的数字");
				this.textBox增减值.Text = "";
				e.Handled = true;
			}
			/*第一位是0，第二位必须为小数点*/
			if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0")
			{
				MessageBox.Show("请输入正确的数字");
				this.textBox增减值.Text = "";
				e.Handled = true;
			}
			/*第一位是负号，第二位不能为小数点*/
			if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
			{
				MessageBox.Show("请输入正确的数字");
				this.textBox增减值.Text = "";
				e.Handled = true;
			}
		}

        private void simpleButton确定_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.textBox增减值.Text))
            {
                this.VALUE = 0;
            }
            else
            {
                this.VALUE = Convert.ToDouble(this.textBox增减值.Text);
            }
            if (this.VALUE > 0)//加
            {
                String str = RestCall.PostHttp(URL.接口url+"/inventory/stockIn?fabricNo=" + this.fabric + "&quantity=" + this.VALUE, "");
                this.Close();
            }
            else//减
            {
                String str = RestCall.PostHttp(URL.接口url + "/inventory/stockOut?fabricNo=" + this.fabric + "&quantity=" + this.VALUE, "");
                this.Close();
            }
        }
    }
    
}
